package com.zk.algorithm;

public class FriendCircles {

    public static void main(String...args) {
        System.out.println(new FriendCircles().findCircleNum(new int[][]{
                {1,1,0},
                {1,1,0},
                {0,0,1}
        }));
    }

    public int findCircleNum(int[][] M) {
        UnionFind unionFind = new UnionFind(M.length);
        int length = M.length;

        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length; j++) {
                if (i == j) {
                    continue;
                }

                if (M[i][j] == 1) {
                    unionFind.union(i, j);
                }

            }
        }

        return unionFind.size();
    }

}
